#include "fb_drv.h"
#include "stdio.h"

fb_card cardfb;

unsigned char color_buffer[1920*1080*4]={0};

#define RED16    0xF800
#define GREEN16  0xFFE0
#define BLUE16     0x001F
#define WHITE16    0xFFFF
#define BLACK16    0x0000

#define RED24    0x0000ff
#define GREEN24  0x00ff00
#define BLUE24     0xff0000
#define WHITE24    0xFFFFFF
#define BLACK24    0x000000

void fill_color16(short *fb_addr, short bit_map, int psize)
{
    int i;
    for(i=0; i<psize; i++) {
        *fb_addr = bit_map;
        fb_addr++;
    }
}
void fill_color24(char *fb_addr, unsigned int bit_map, int psize)
{
    int i;
    char *p=fb_addr;
    for(i=0; i<psize; i++) {
        *p =bit_map ;
        p++;
        *p =bit_map >>8 ;
        p++;
        *p =bit_map >>16 ;
        p++;
    }
}


void signed_fb_refresh(){
    int num=10;
    fb_card_init(&cardfb,"/dev/fb0");
    fb_card_print_info(cardfb);

    fb_switch_buffer(&cardfb,1);

    /* 24 map  */
    while(num--) {
        printf("\ndrawing blue......\n");

        fill_color24((char *)color_buffer, BLUE24, 1920*1080);
        fb_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);

        printf("\ndrawing green......\n");
        fill_color24((char *)color_buffer, GREEN24, 1920*1080);
        fb_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);

        printf("\ndrawing RED......\n");
        fill_color24((char *)color_buffer, RED24, 1920*1080);
        fb_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);
    }
}

void double_fb_refresh(){
    int num=10;
    fb_card_init(&cardfb,"/dev/fb0");
    fb_card_print_info(cardfb);

    /* 24 map  */
    while(num--) {
        printf("\ndrawing blue......\n");

        fill_color24((char *)color_buffer, BLUE24, 1920*1080);
        fb_double_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);

        printf("\ndrawing green......\n");
        fill_color24((char *)color_buffer, GREEN24, 1920*1080);
        fb_double_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);

        printf("\ndrawing RED......\n");
        fill_color24((char *)color_buffer, RED24, 1920*1080);
        fb_double_cpy(&cardfb,color_buffer,cardfb.screen_size);
        sleep(2);
    }
}


int main (int argc ,char** argv){

//    signed_fb_refresh();

    double_fb_refresh();

    while(1){
        sleep(1);
    }

    return 0;
}
